<template>

	<!-- Modal container, shown conditionally -->
	<!-- -->
	<view class="modal-overlay" :class="{'modal-block':isModalVisible}" @click="Cancel">
		<view class="login" :style="{ 'background-image': `url(${bg})` }" :class="{'login-block':isModalVisible}">
			<view class="login-box">

				<view class="tit-img">
					<image v-if="score<24" :src="one" mode=""></image>
					<image v-if="score>=24 && score<40" :src="two" mode=""></image>
					<image v-if="score>=40 && score<60" :src="three" mode=""></image>
					<image v-if="score>=60 && score<=100" :src="four" mode=""></image>
				</view>
				<view class="mark">
					{{score}}分
				</view>
				<view class="synthesis">
					综合得分
				</view>
				<view class="hint">
					{{getHint()}}
				</view>
				<view class="btn-box">
					<view class="btn-qu" @click="viewDetails">
						查看详情
					</view>
					<view class="btn">
						<view class="">
							让好友测一测
						</view>
						<button open-type="share">分享</button>
					</view>
				</view>
			</view>
		</view>
		<view class="down" @click="Cancel">
			<image :src="ximg" mode=""></image>
		</view>
	</view>



</template>

<script>
	import config from "../utils/config";
	import {
		toast,
		getStore,
		setStore,
		removeStore
	} from "@/utils/index";
	import {
		listByIds,
		logout,
		getPhone,
		wxlogin
	} from '@/service/api.js';
	export default {
		data() {
			return {
				result: [{
					"title": "暂缓行动，先调体质",
					"score": "24",
					"hint": "您现阶段对减肥的认知较为薄弱，且可能身体状态并不适合立即进行减肥，建议先通过中医调理体质，如改善便秘、增强脾胃功能等亚健康，待身体状态稳定后再考虑减肥计划，健康是减肥的前提，切勿急于求成。"
				}, {
					"title": "加倍努力",
					"score": "40",
					"hint": "您在减肥方面的认知还需进一步强化，通过提高治疗次数，和医生相互配合，充分认识减肥的重要性与科学性，您的减肥之路将不再艰难，但需注意避免盲目跟风，否则失败率极高。"
				}, {
					"title": "预祝成功",
					"score": "60",
					"hint": "您对减肥有一定的了解，但仍有提升空间，通过深入沟通、调整减肥方案，并结合中医减肥的理念，如平衡阴阳、调和气血，您的减肥之路将更加顺畅，成功机会大增。"
				}, {
					"title": "恭喜您",
					"score": "100",
					"hint": "您已经具备了较高的减肥认知与实践基础，结合中医减肥的疗法，如调理脾胃、疏通经络，您的减肥成功比例极高，期待您健康美丽的蜕变。"
				}],
				ximg:config.ossHost + '2024/12/29/ef0098ae83b74d3281c0db895b36db84.png',
				//背景大图
				bg: config.ossHost + '2024/12/29/82f933a4436a4ea98ecaa03c9ef3a41f.png',
				one: config.ossHost + "2024/12/29/c486497537054fa8b659d1bbf49d5397.png",
				two: config.ossHost + "2024/12/29/c486497537054fa8b659d1bbf49d5397.png",
				three: config.ossHost + "2024/12/29/c486497537054fa8b659d1bbf49d5397.png",
				four: config.ossHost + "2024/12/29/c486497537054fa8b659d1bbf49d5397.png",

				isModalVisible: false,
				score: 0,
				questions: [],
			}
		},
		props: {
			Visible: {
				type: Boolean,
				required: false,
			},
			totalScore: {
				type: Number,
				require: 0,
			},
			selectedAnswers: {
				type: Array,
				default () {
					return [];
				}
			},
		},
		watch: {
			Visible(newTitle) {

				this.isModalVisible = newTitle
			},
			totalScore(newTitle) {
				// this.getHint();
				this.score = newTitle
			},
			selectedAnswers(newTitle) {
				
				this.questions = newTitle
			}
		},
		computed: {
		    resultTitle() {
		      // 将 score 转换为数字
		     
		    
		      // result 数组
		      const result = this.result;
		
		      // 查找score对应的区间并返回对应的title
		      for (let i = 0; i < result.length; i++) {
		        const currentScore = parseInt(result[i].score); // 当前区间的 score
		        const nextScore = i < result.length - 1 ? parseInt(result[i + 1].score) : Infinity; // 下一个区间的 score 或 Infinity
		
		        // 如果 score 落在当前区间内
		        if (this.score >= currentScore && this.score < nextScore) {
		          return result[i].title;
		        }
		      }
		
		      // 如果没有匹配的区间，返回默认值（如果需要）
		      return "暂缓行动，先调体质";
		    }
		  },
		methods: {
			//查看详情
			viewDetails() {
				
				
				uni.navigateTo({
					url: `/outpatient/score/index?score=${this.score}&resultTitle=${this.resultTitle}&getHint=${this.getHint()}`
				});
			},
			getHint() {
				// 根据父组件传递的 score 进行过滤
				const filtered = this.result.filter(item => parseInt(item.score) >= this.score);
				return filtered.length > 0 ? filtered[0].hint : '暂无提示信息';
			},

			// Show the modal
			showModal() {
				this.isModalVisible = true;
			},
			// Hide the modal
			Cancel() {
				this.isModalVisible = false;
				this.$emit('isModal', this.isModalVisible)
			},

		}

	}
</script>

<style lang="scss" scoped>
	/* Modal overlay background */
	.modal-overlay {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background: rgba(0, 0, 0, 0.5);
		/* Dark semi-transparent background */
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		z-index: -1;
		opacity: 0;
		transition: opacity 0.25s ease-in-out;
	}

	.modal-block {
		z-index: 1000;
		opacity: 1;
	}

	/* Modal container */
	.login {
		text-align: center;


		border-radius: 8px;

		width: 750rpx;
		height: 904rpx;
		background-repeat: no-repeat;
		background-size: 100% 100%;
		opacity: 0;
		transform: translateY(-30rpx);
		transition: opacity 0.25s ease-in-out, transform 0.25s ease-in-out;

		.login-box {
			width: 750rpx;
			height: 904rpx;
			padding-top: 290rpx;
			position: relative;
		}

		.tit-img {
			position: absolute;
			top: 64rpx;
			width: 616rpx;
			height: 264rpx;
			margin-left: -308rpx;
			left: 50%;

			image {
				width: 616rpx;
				height: 264rpx;
			}
		}

		.mark {
			font-family: Alibaba Health Font 2.0 CN, Alibaba Health Font 20 CN;
			font-weight: normal;
			font-size: 96rpx;
			background: linear-gradient(90deg, #CCA566 0%, #805D33 100%);
			-webkit-background-clip: text;
			/* 让背景渐变应用到文字上 */
			background-clip: text;
			/* 标准语法 */
			color: transparent;
			/* 使文本颜色透明，从而只显示背景渐变 */

			font-style: normal;
		}

		.synthesis {
			font-size: 32rpx;
			color: #CCA566;
		}

		.hint {
			width: 590rpx;
			margin: auto;
			margin-top: 16rpx;
			font-size: 24rpx;
			color: #805D33;
		}

		.btn-box {
			display: flex;
			justify-content: center;
			margin-top: 36rpx;

			view {
				width: 272rpx;
				height: 94rpx;
				line-height: 94rpx;
				text-align: center;
				color: #CCA566;
				border-radius: 60rpx 60rpx 60rpx 60rpx;
				border: 2rpx solid #CCA566;
			}

			.btn {
				margin-left: 32rpx;
				position: relative;
				border: none;

				button {
					position: absolute;
					top: 0;
					left: 0;
					opacity: 0;
					width: 272rpx;
					height: 94rpx;
				}
			}
		}
	}

	.login-block {
		opacity: 1;
		/* Fade in content */
		transform: translateY(0);
		/* Slide in from top */
	}

	.down {
		width: 64rpx;
		height: 64rpx;

		margin-top: -48rpx;

		image {
			width: 64rpx;
			height: 64rpx;
		}
	}
</style>